package com.ytjj.qmyx.users.utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * @Description TODO
 *
 * @Version 1.0
 * 
 */
public class AuthUtil {

    public static JSONObject getAuthJson(String url) throws IOException {
        JSONObject jsonObject = null;
        //获取DefaultHttpClient请求
        HttpClient client = HttpClientBuilder.create().build();
        HttpGet httpGet = new HttpGet(url);
        HttpResponse response = client.execute(httpGet);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String result = EntityUtils.toString(entity);
            jsonObject = (JSONObject) JSONObject.parse(result);
        }
        httpGet.releaseConnection();
        return jsonObject;
    }
}
